interface IObj {
  title?: string;
  content?: string;
  showCancel?: boolean;
  cancelText?: string;
  cancelColor?: string;
  confirmText?: string;
  confirmColor?: string;
  confirm?: () => void;
  cancel?: () => void;
}

const showModal = function (obj: IObj): Promise<{ confirm: boolean }> {
  return new Promise((resolve, reject) => {
    uni.showModal({
      title: obj.title || '提示',
      content: obj.content || '',
      showCancel: !!(obj.showCancel || obj.showCancel === undefined),
      cancelText: obj.cancelText || '确定',
      cancelColor: obj.cancelColor || '#2d84fb',
      confirmText: obj.confirmText || '取消',
      confirmColor: obj.confirmColor || '#333333',
      success: (res) => {
        if (res.confirm) {
          reject(res);
          obj.cancel && obj.cancel();
        } else {
          resolve(res);
          obj.confirm && obj.confirm();
        }
      },
    });
  });
};
export default showModal;
